﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace csvmb.testdatengenerator
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Anzahl Datensätze: ");
            var n = int.Parse(Console.ReadLine());

            Console.Write("Anzahl Spalten: ");
            var s = int.Parse(Console.ReadLine());

            var dateiname = string.Format("test-{0}x{1}.csv", s, n);

            using (var sw = new StreamWriter(dateiname, false, Encoding.UTF8))
            {
                Spaltennamen_schreiben(sw, s);
                Datensätze_generieren(sw, n, s);
            }
        }


        private static void Spaltennamen_schreiben(StreamWriter sw, int s)
        {
            sw.Write("Index");
            for (var i = 0; i < s; i++)
                sw.Write(";Spalte{0}", i);
            sw.WriteLine();
        }

        
        private static void Datensätze_generieren(StreamWriter sw, int n, int s)
        {
            for (var i = 0; i < n; i++)
            {
                Datensatz_generieren(sw, i, s);
                if (i % 10000 == 0)
                    Console.WriteLine("{0} = {1:0.0}%", i, (double)i/(double)n*100.0);
            }
        }

        private static void Datensatz_generieren(StreamWriter sw, int index, int s)
        {
            sw.Write(index);
            for (var i = 0; i < s; i++)
                sw.Write(";{0}", Wert_generieren());
            sw.WriteLine();
        }


        private static Random rnd = new Random();

        private static string Wert_generieren()
        {
            string wert = "A";
            var x = rnd.Next(15);
            for (var i = 1; i < x; i++)
                wert += new string(Encoding.ASCII.GetChars(new byte[] {(byte) (97 + i)}));
            return wert;
        }
    }
}
